﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_PERMISSION.Base;
using ERP_RORZE_PRODUCT.Product.database;

namespace ERP_RORZE_PRODUCT.Product.PartData
{
    public partial class frm_MaterialAdd : DevExpress.XtraEditors.XtraForm
    {
        ClsPartDataDAO clsPartdataDAO = new ClsPartDataDAO();
        DataTable dt;
        ClsMaterialTable obj = new ClsMaterialTable();
        public event EventHandler Reload;
        private LogUtils log;

        public frm_MaterialAdd()
        {
            InitializeComponent();
            log = new LogUtils();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtMaterialID.Text == "")
            {
                MessageBox.Show("chưa nhập MaterialID");
            }
            else if (txtDensity.Text == "")
            {
                MessageBox.Show(" chưa nhập Density");
            }
            else
            {
                try
                {
                    obj.Density = float.Parse(txtDensity.Text);
                    obj.MaterialID = txtMaterialID.Text;
                    obj.Type = txtType.Text;
                    obj.UnitPrice = decimal.Parse(txtUnitPrice.Text);
                    clsPartdataDAO.InsertMaterial(txtMaterialID.Text, txtDensity.Text, txtType.Text, txtUnitPrice.Text);

                    //write Log
                    log.Table = LogConstant.Table.Product.MaterialList;
                    log.Task = LogConstant.Task.Insert;
                    log.Description = "MaterialID: " + obj.MaterialID;
                    log.WriteLog();

                    MessageBox.Show("Đã nhập xong");
                    //Reload(sender, e);
                    txtMaterialID.Text = "";
                    txtDensity.Text = "";
                    txtType.Text = "";
                    txtUnitPrice.Text = "";
                    txtMaterialID.Focus();
                }
                catch
                {
                    MessageBox.Show("Density là kiểu số thực và UnitPrice là kiểu money");
                }
            }
        }
        protected override bool ProcessKeyPreview(ref Message m)
        {
            if (m.Msg == 0x0100 && (int)m.WParam == 13)
            {
                this.ProcessTabKey(true);
            }
            return base.ProcessKeyPreview(ref m);
        }
    }
}